using MyToDo.Common;
using MyToDo.Shared.Dtos;
using System.Windows;
using System.Windows.Controls;

namespace MyToDo.Views
{
    /// <summary>
    /// AttachedPropertyDemoView.xaml 的交互逻辑
    /// </summary>
    public partial class AttachedPropertyDemoView : UserControl
    {
        public AttachedPropertyDemoView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 编辑按钮点击事件处理程序
        /// 演示如何从附加属性中获取绑定的对象
        /// </summary>
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            // 从发送者(按钮)获取附加属性TagObject的值
            var button = sender as Button;
            if (button != null)
            {
                // 使用附加属性的Get方法获取绑定的备忘录对象
                var memoDto = AttachedProperties.GetTagObject(button) as MemoDto;
                
                if (memoDto != null)
                {
                    // 显示选中的备忘录信息
                    SelectedMemoInfo.Text = $"选中的备忘录: {memoDto.Title} (ID: {memoDto.Id})";
                }
            }
        }
    }
}